<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset id="searchFieldset_currentTable" class="table-search-fieldset">
            <legend>{:lang("common.condition_search")}</legend>
            <form class="layui-form layui-form-pane form-search">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.start_date")}</label>
                    <div class="layui-input-inline">
                        <input id="startDate" name="d_progress_date_ge" class="layui-input cssDate"
                               placeholder="{:lang('common.choose')}{:lang('common.start_date')}"
                               value="{$param.d_progress_date_ge|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.end_date")}</label>
                    <div class="layui-input-inline">
                        <input id="endDate" name="d_progress_date_le" class="layui-input cssDate"
                               placeholder="{:lang('common.choose')}{:lang('common.end_date')}"
                               value="{$param.d_progress_date_le|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("accounting.name")}</label>
                    <div class="layui-input-inline">
                        <select name="m_accounting_id_eq" lay-search>
                            <option value="">{:lang("common.choose")}{:lang("accounting.name")}</option>
                            {foreach :getAccountingList() as $val}
                            <option value="{$val.id}" {if $val.id==$param.m_accounting_id_eq}selected{/if}>{$val.name}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline" style="margin-left:50px">
                    <button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch"
                            lay-submit>{:lang("common.btn_search")}
                    </button>
                </div>

                {if auth('tally.Stat/exportByAccounting')}
                <div class="layui-form-item layui-inline" style="margin-left:20px">
                    <button type="button" class="layui-btn layui-btn-success"
                            onclick="exportExcel('/tally.Stat/exportByAccounting?')">
                        {:lang("common.btn_export")}
                    </button>
                </div>
                {/if}
            </form>
        </fieldset>

        <table class="layui-table">
            <thead>
            <tr>
                <th>{:lang('accounting.username_alias')}</th>
                <th>{:lang('accounting.name')}</th>
                <th>{:lang('accounting.cost')}</th>
                <th>{:lang('custom.name')}</th>
                <th>{:lang('stat.total_time')}</th>
                <th>{:lang('accounting.total_cost')}</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $vo }
            <tr>
                <td rowspan="{:count($vo.list)}">{$vo.username}</td>
                <td rowspan="{:count($vo.list)}">{$vo.nickname}</td>
                <td rowspan="{:count($vo.list)}">{$vo.cost}</td>
                <td>{$vo['list'][0]['custom_name']}</td>
                <td data-field="total_time">
                    <a href="#" onclick="return openDetail({$vo.accounting_id},{$vo['list'][0]['custom_id']})">
                        {$vo['list'][0]['total_time']}
                    </a>
                </td>
                <td rowspan="{:count($vo.list)}" data-field="money">{$vo.money}</td>
            </tr>
            {foreach $vo.list as $idx=>$it }
            {if $idx > 0 }
            <tr class="{if $it.custom_id==0 }layui-table-total{/if}">
                <td>{$it.custom_name}</td>
                {if $it.custom_id> 0 }
                <td data-field="total_time">
                    <a href="#" onclick="return openDetail({$vo.accounting_id},{$it['custom_id']})">{$it.total_time}</a>
                </td>
                {else/}
                <td>{$it.total_time}</td>
                {/if}
            </tr>
            {/if}
            {/foreach}
            {/foreach}
            </tbody>
            <tfoot>
            <tr class="layui-table-total auto-compute-total">
                <td colspan="4">{:lang('common.total')}</td>
                <td data-field="total_time"></td>
                <td data-field="money"></td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script>
    layui.use(['myApp'], function () {
        let $ = layui.jquery
            , myCommon = layui.myCommon;
        window.openDetail = function (accountingId, customId) {
            let addr = 'tally.todo/index?limit=100000&c_id_eq=' + customId + '&a_id_eq=' + accountingId;
            if ($('#startDate').val() != '') {
                addr += '&d_progress_date_ge=' + $('#startDate').val();
            }
            if ($('#endDate').val() != '') {
                addr += '&d_progress_date_le=' + $('#endDate').val();
            }
            return popupWindow('{:lang("common.detail_list")}', addr);
        }
        myCommon.listen();
    });
</script>
